//
//  ShowCellLayout.m
//  sensen_ios
//
//  Created by justiOS on 16/5/4.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ShowCellLayout.h"

@implementation ShowCellLayout
- (void)setModel:(PostModel *)model {
    _model = model;
    // 11.单元格尺寸
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = SCREEN_WIDTH;
    CGFloat h = (SCREEN_HEIGHT  - SCREEN_WIDTH * 0.9 - 64 - 49) / 2 ;
    if (SCREEN_WIDTH == 320) {
        h = h + 40;
        if (SCREEN_HEIGHT == 480) {
            h = h + 20;
        }
    }
    _cellRect = CGRectMake(x, y, w, h);
    
    // 1.头像
    CGFloat iconX = 10;
    CGFloat iconY = 5;
    CGFloat iconW = 35;
    CGFloat iconH = iconW;
    _iconRect = CGRectMake(iconX, iconY, iconW, iconH);
    
    // 2.昵称
    CGFloat nickX = CGRectGetMaxX(_iconRect) + 5;
    CGFloat nickY = iconY;
    CGFloat nickW = SCREEN_WIDTH - nickX - 120;
    CGFloat nickH = 20;
    _nickRect = CGRectMake(nickX, nickY, nickW, nickH);
 
    // 4.图片
    CGFloat imgX = 10;
    CGFloat imgY = CGRectGetMaxY(_iconRect) + 5;
    CGFloat imgW = 70;
    CGFloat imgH = h - 55;
     _imgRect = CGRectMake(imgX, imgY, imgW, imgH);
    
    //  标题
    CGFloat titleX = CGRectGetMinX(_iconRect);
   
    CGFloat titleY = CGRectGetMaxY(_iconRect) + 5;
    CGFloat titleW = SCREEN_WIDTH - 10 * 2;
    CGFloat titleH = 20;
    if (model.imgAry.count >= 1) {
        titleX = CGRectGetMaxX(_imgRect) + 10;
        titleW = SCREEN_WIDTH - 10 * 3 - 70;
    }
    _titleRet = CGRectMake(titleX, titleY, titleW, titleH);
    
    // 3.内容
    CGFloat contentX = titleX;
    CGFloat contentY = CGRectGetMaxY(_titleRet);
    CGFloat contentW = titleW;
    CGFloat contentH = h - 50 - 20;
    _contentRect = CGRectMake(contentX, contentY, contentW, contentH);
    

    // 6.帖子创建时间
    CGFloat timeX = CGRectGetMaxX(_iconRect) + 5;
    CGFloat timeY = CGRectGetMaxY(_nickRect);
    CGFloat timeW = [_model.dateline_show getSizeOfString:12].width; //TODO: 宽度最后都应该根据字符串的长度计算
    CGFloat timeH = 15;
    _timeRect = CGRectMake(timeX, timeY, timeW, timeH);
    
    // 7-8.评论和评论图片
    CGFloat commentX;
    CGFloat commentY = 15;
    CGFloat commentW = [_model.replies getSizeOfString:13].width; //TODO: 宽度最后都应该根据字符串的长度计算
    CGFloat commentH = 20;
    commentX = SCREEN_WIDTH - 10 - commentW;
    _commentRect = CGRectMake(commentX, commentY, commentW, commentH);
    CGFloat commentImgX;
    CGFloat commentImgY = 15;
    CGFloat commentImgW = 20;
    CGFloat commentImgH = 20;
    commentImgX = CGRectGetMinX(_commentRect) - 5 - commentImgW;
    _commentImgRect = CGRectMake(commentImgX, commentImgY, commentImgW, commentImgH);
    
    // 9-10.评论和评论图片
    CGFloat favourX;
    CGFloat favourY = 15;
    CGFloat favourW = [_model.likes getSizeOfString:13].width; //TODO: 宽度最后都应该根据字符串的长度计算
    CGFloat favourH = 20;
    favourX = CGRectGetMinX(_commentImgRect) - 10 - favourW;
    _favourRect = CGRectMake(favourX, favourY, favourW, favourH);
    CGFloat favourImgX;
    CGFloat favourImgY = 15;
    CGFloat favourImgW = 20;
    CGFloat favourImgH = 20;
    favourImgX = CGRectGetMinX(_favourRect) - 5 - favourImgW;
    _favourImgRect = CGRectMake(favourImgX, favourImgY, favourImgW, favourImgH);
    
    

}
@end
